package com.example.homework.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.homework.R;
import com.example.homework.pojo.Note;

import java.util.ArrayList;
import java.util.List;

/**
 * @作者 zhaichenji
 * @创建日期 2022/4/17 11:40
 * @包名 com.example.homework.adapter
 * @版本 1.0
 * @描述
 */
public class ListViewAdapter extends BaseAdapter {
    private LayoutInflater layoutInflater;
    private ArrayList list;

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.note_listview_item, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }


        return convertView;
    }

    class ViewHolder {
        TextView tv_note_text;
        TextView tv_note_time;

        public ViewHolder(View view) {
            tv_note_text = view.findViewById(R.id.note_text);
            tv_note_time = view.findViewById(R.id.note_time);
        }
    }
}
